package com.time.company.components.popup;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.time.company.R;
import com.time.company.base.BasePW;

/**
 * 删除操作的PW
 * Author: Created by deng on 2016/8/16.
 * E-mail: tx16bing@163.com
 */
public class DeletePW extends BasePW implements View.OnClickListener {

    private Context mContext;
    private String deleteId, title;

    public TextView tvLeftButton,tvRightButton;

    public LinearLayout llCancel,llConfirm;

    public DeletePW(Context context, ViewGroup view, String deleteId) {
        this(context, view, deleteId, "");
    }

    public DeletePW(Context context, ViewGroup view, String deleteId, String title){
        this.mContext = context;
        this.deleteId = deleteId;
        if (!TextUtils.isEmpty(title)){
            this.title = title;
        }else {
            this.title = mContext.getString(R.string.pw_delete_default_title);
        }

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View mView = inflater.inflate(R.layout.pw_delete, view, false);
        assignViews(mView);
        setContentView(mView);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        setFocusable(true);
        setOutsideTouchable(true);
//        this.setAnimationStyle(R.style.CsbBank_Pw_Bottom_Animation);
        ColorDrawable dw = new ColorDrawable(0x80000000);
        this.setBackgroundDrawable(dw);
        mView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                dismiss();
                return true;
            }
        });
    }

    private void assignViews(View mView) {
        TextView tvTitle = (TextView) mView.findViewById(R.id.tv_delete_title);
        tvTitle.setText(this.title);
        tvLeftButton=(TextView)mView.findViewById(R.id.tv_left_button);
        tvRightButton=(TextView)mView.findViewById(R.id.tv_right_button);
        llCancel = (LinearLayout) mView.findViewById(R.id.ll_delete_cancel);
        llConfirm = (LinearLayout) mView.findViewById(R.id.ll_delete_confirm);
        llCancel.setOnClickListener(this);
        llConfirm.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (onItemClickListener != null) {
            if (view.getId() == R.id.ll_delete_confirm) {
                onItemClickListener.onItemClick(11, deleteId);
                dismiss();
            } else {
                dismiss();
            }
        }

    }

}
